<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    ${r'<#assign base=request.contextPath />'}
    ${r'<#setting  number_format="0.##"/>'}
    <base id="base" href="${r'${base}'}">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${r'${base}'}/backstage/layui-v2.5.6/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${r'${base}'}/backstage/layui-v2.5.6/layui/css/style.css" media="all">
    <script src="${r'${base}'}/backstage/js/jquery-1.8.3.min.js?t=1"></script>
    <script src="${r'${base}'}/backstage/js/ipNameUrl.js"></script>
    <script src="${r'${base}'}/backstage/layui-v2.5.6/layui/layui.js?t=1"></script>
    <script src="${r'${base}'}/backstage/js/feng.js?t=1"></script>
    <script>
        var base =  ${r'"${base}"'};
    </script>
</head>
<body>
<br>
<form class="layui-form " action="">
    <#list fields as field>
    <#if field.keyFlag==false>
        <#if field.propertyName=="createTime">
            <#else>
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.comment}</label>
                    <div class="layui-input-block">
                        <input type="text" id="${field.propertyName}" name="${field.propertyName}"   autocomplete="off" placeholder="请输入${field.comment}"
                               class="layui-input">
                    </div>
                </div>
        </#if>
    </#if>
    </#list>
    <div style="float: right;margin-right: 5%">
        <button type="button" class="layui-btn layui-btn-danger" onclick="saveButton()">保存</button>
        <button type="button" class="layui-btn" style="background: #9F9F9F" onclick="window.history.back(-1);">返回</button>
    </div>
</form>

<script>
    layui.use(['form', 'layer', 'layedit', 'laydate'], function() {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
    });

    //添加
    function saveButton() {
        layui.layer.msg("正在提交添加信息...", {icon: 7, time: 10000, shade: [0.8, '#000', true]}); //添加laoding,0-2两种方式
        <#list fields as field>
            if ($("#${field.propertyName}").val() == "") {
                layui.layer.msg("${field.comment}不能为空", {icon: 5, time: 1000, shade: [0.6, '#000', true]});
                return;
            }
        </#list>
        var jsonDate = {
            <#list fields as field>
                <#if field.keyFlag==false>
                    <#if field_has_next>
                        <#if field.propertyName=="createTime">
                            <#else >
                            ${field.propertyName}:$("#${field.propertyName}").val(),
                        </#if>
                    <#else>
                        <#if field.propertyName=="createTime">
                            <#else >
                            ${field.propertyName}:$("#${field.propertyName}").val()
                        </#if>
                    </#if>
                </#if>
            </#list>
        }
        $.ajax({
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            url: base+"/admin/${htmlFinName}/saveOrUpdate${htmlName}",
            data: JSON.stringify(jsonDate),
            success: function (data) {
                if (data.code === 200) {
                    setTimeout(function () {
                        layer.closeAll();
                        window.location.href = base+"/admin/${htmlFinName}/main.html"
                    }, 1000)
                } else {
                    layui.layer.msg(data.msg, {icon: 5, time: 1000, shade: [0.6, '#000', true]});
                }
            }
        });
    }
</script>
</body>
</html>